Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

cleos to display pushed actions' return values #9375

Merged
merged 13 commits into from
Aug 12, 2020

Conversation

Max-B1
Copy link
Contributor

@Max-B1 Max-B1 commented Aug 7, 2020

Change Description

After abi_serializer was updated (#9354) it's time to utilize return values passed by nodeos in cleos. cleos now is capable of displaying the actual return values or their hashes. The new output line starts with => followed by return value:/return value (hex): and the return value.

If the return_value_data field of returned json is present cleos will display it.
If return_value_data is missing and return_value_hex_data is present cleos will display value of return_value_hex_data.
If return_value_data is missing and return_value_hex_data is empty (there is no return value)

Example:

#         eosio <= eosio::test_action_rv        {"userid":0,"items":[0],"status":"shipped"}
=>                                return value: {"id":25,"userid":0,"items":[0],"status":"shipped","total":"0.00000000000000000"}
#         eosio <= eosio::test_action           {"id":25,"userid":0,"items":[0],"status":"shipped"}

or

#         eosio <= eosio::test_action_hex_rv    {"userid":0,"items":[0],"status":"pending"}
=>                          return value (hex): 1800000001000770656e64696e6700000000

Change Type

Select ONE

  • Documentation
  • Stability bug fix
  • Other
  • Other - special case

Consensus Changes

  • Consensus Changes

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

cleos will have an extra line for actions that return values. The line will be prefixed with =>. Example actions rstring() and ruint() return values passed into them:

> cleos push action eosio rstring '{"str":null}'  -p eosio@active
executed transaction: 1e72a3ef1fa01a9c90b870fe86bf31413c6a2f40a2722ca72d9dd707f58851af  96 bytes  116 us
#         eosio <= eosio::rstring               {"str":""}
=>                                return value: ""

> cleos push action eosio rstring '{"str":"test"}'  -p eosio@active
executed transaction: 2484ba021683bb3c6daaabe291ba291e2689d1be899a293d0a09cc68cf0967fb  96 bytes  116 us
#         eosio <= eosio::rstring               {"str":"test"}
=>                                return value: "test"

> cleos push action eosio ruint '{"i":42}'  -p eosio@active
executed transaction: 12c51fd27fad9bb0fa959037a72093ad0b168f5846e916a0e9a295c8416bdf9f  96 bytes  138 us
#         eosio <= eosio::ruint                 {"i":42}
=>                                return value: 42

It can work with structures/classes as well. For a struct like this:

struct tmp {
    uint32_t id = 1;
    std::vector<uint8_t> list{ 1, 2 };

    EOSLIB_SERIALIZE(tmp, (id)(list))
};

and rtmp() returning a default tmp object, output will look like this:

> cleos push action eosio rtmp '{}'  -p eosio@active
executed transaction: 42386687d94695d77d67cf901cf8d1a4f83ac9f89382f0b01f3fb51267cc21cd  96 bytes  110 us
#         eosio <= eosio::rtmp                  ""
=>                                return value: {"id":1,"list":[1,2]}

When it wont be possible to decode the return value, output will look like this

=>                          return value (hex): 1400000001000770656e64696e6700000000

If length on a return value string is more than 100 chars the string will be truncated to the first 100 chars and ... will be added at the end. It's similar to what cleos does to action parameters output.

> cleos push action eosio rstring '{"str":"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}'  -p eosio@active
executed transaction: 9fb35c72dbccadb4ff7b72a3a046543fbe2ae36eea70265f2b8356e8192c3f0e  248 bytes  176 us
#         eosio <= eosio::rstring               {"str":"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
=>                                return value: "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

@Max-B1 Max-B1 requested review from heifner and iamveritas August 7, 2020 23:01
programs/cleos/main.cpp Outdated Show resolved Hide resolved
const auto & iter = at.get_object().find("return_value_data");
if( iter != at.get_object().end() ) {
return_value = fc::json::to_string(iter->value(), fc::time_point::maximum());
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if you have to check "return_value_hex_data", too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, "return_value_hex_data" will always be present(#9354)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you interact with an older version of nodeos? You need to support older nodeos versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a check for return_value_hex_data as well

@Max-B1 Max-B1 merged commit bacc5f0 into develop Aug 12, 2020
@brianjohnson5972 brianjohnson5972 deleted the EPE-202_cleos_and_return_values branch November 21, 2020 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants